using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Controls;
using Microsoft.Practices.CompositeUI.SmartParts;
using Microsoft.Practices.CompositeUI.Utility;

namespace SCSFContrib.CompositeUI.WPF.Workspaces
{
	/// <summary>
	/// Provides information to the <see cref="TabWorkspace"/> when displaying smart parts.
	/// </summary>
	public class TabSmartPartInfo : SmartPartInfo
	{
		private object _header;
		private TabPosition _position;
		private bool _activate;

		/// <summary>
		/// Gets or sets the header for the tab item.
		/// </summary>
		/// <remarks>
		/// <para>
		/// This property allows rich content to be used for a tab header, rather than just a <c>string</c>. If this property is not set (or is
		/// set to <see langword="null"/>), it will return <see cref="SmartPartInfo.Title"/>.
		/// </para>
		/// </remarks>
		public object Header
		{
			get
			{
				return _header ?? Title;
			}
			set
			{
				_header = value;
			}
		}

		/// <summary>
		/// Gets or sets the position at which the tab should be displayed.
		/// </summary>
		public TabPosition Position
		{
			get
			{
				return _position;
			}
			set
			{
				_position = value;
			}
		}

		/// <summary>
		/// Gets or sets a value indicating whether the tab should be activated when displayed.
		/// </summary>
		public bool Activate
		{
			get
			{
				return _activate;
			}
			set
			{
				_activate = value;
			}
		}

		/// <summary>
		/// Constructs an instance of <c>TabSmartPartInfo</c>.
		/// </summary>
		public TabSmartPartInfo()
		{
			_activate = true;
			_position = TabPosition.End;
		}

		/// <summary>
		/// Constructs an instance of <c>TabSmartPartInfo</c> with the specified header.
		/// </summary>
		/// <param name="header">
		/// The header for the tab.
		/// </param>
		public TabSmartPartInfo(object header)
			: this()
		{
			_header = header;
		}

		/// <summary>
		/// Applies the properties of this <c>TabSmartPartInfo</c> to <paramref name="tabItem"/>.
		/// </summary>
		/// <remarks>
		/// <para>
		/// This method should apply all relevant properties of this <c>TabSmartPartInfo</c> to <paramref name="tabItem"/>.
		/// Some properties, such as <see cref="Position"/>, cannot be applied. Such properties should be ignored.
		/// </para>
		/// </remarks>
		/// <param name="tabItem">
		/// The <see cref="TabItem"/> to which properties will be applied.
		/// </param>
		internal virtual void ApplyTo(TabItem tabItem)
		{
			Guard.ArgumentNotNull(tabItem, "tabItem");
			tabItem.Header = Header;
		}
		
		/// <summary>
		/// Applies the properties of this <c>TabSmartPartInfo</c> to <paramref name="smartPartInfo"/>.
		/// </summary>
		/// <param name="smartPartInfo">
		/// The <c>TabSmartPartInfo</c> to be updated.
		/// </param>
		internal virtual void ApplyTo(TabSmartPartInfo smartPartInfo)
		{
			Guard.ArgumentNotNull(smartPartInfo, "smartPartInfo");
			smartPartInfo._header = _header;
			smartPartInfo._position = _position;
			smartPartInfo._activate = _activate;
		}
	}
}
